package com.softer.chengxin.system.controller;

import com.softer.chengxin.common.domin.CommonResult;
import com.softer.chengxin.common.enums.ResultEnum;
import com.softer.chengxin.system.service.SystemManageService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author Gong Zhiyang
 * @date 2018/10/23
 */
@RestController
public class SystemManageController {
    @Autowired
    private SystemManageService systemManageService;

    /**
     * 修改密码
     *
     * @param oldPwd 旧密码
     * @param newPwd 新密码
     * @return 修改结果
     */
    @PostMapping("/api/systemManager/updatePwd")
    public CommonResult updatePwd(String oldPwd, String newPwd, HttpSession session) {
        if (StringUtils.isEmpty(oldPwd)) {
            return new CommonResult(ResultEnum.FAIL.getCode(), "请输入旧密码");
        }
        if (StringUtils.isEmpty(newPwd)) {
            return new CommonResult(ResultEnum.FAIL.getCode(), "请输入新密码");
        }
        return systemManageService.updatePwd(oldPwd, newPwd, session);
    }

    /**
     * 重置密码
     *
     * @param qyNo 企业账号
     * @return 修改结果
     */
    @RequestMapping("/api/systemManager/passwordReset")
    public CommonResult passwordReset(@RequestParam("qyNo") String qyNo) {
        return systemManageService.resetPassword(qyNo);
    }
}
